import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_douban/config/app_colors.dart';
import 'package:flutter_douban/main_page/home/detail/page/author_page.dart';
import 'package:flutter_douban/main_page/home/detail/page/text_page.dart';
import 'package:flutter_douban/model/cook_info_model.dart';
import 'package:flutter_douban/tool_views/cached_network_Image.dart';
import 'package:flutter_douban/tool_views/custom_text_page.dart';
import 'package:flutter_douban/tool_views/text_page.dart';
import '../attention/collection_image.dart';
import 'avatar_recommend_view.dart';
import 'package:flutter_douban/main_page/home/detail/page/cook_detail_page.dart';

class CooKRecommendView extends StatefulWidget {
  final CookInfoModel model;

  const CooKRecommendView({Key? key, required this.model}) : super(key: key);

  @override
  _CooKRecommendViewState createState() => _CooKRecommendViewState();
}

class _CooKRecommendViewState extends State<CooKRecommendView> {
  @override
  Widget build(BuildContext context) {
    double height = 0;
    if (widget.model.ph == 'null' || widget.model.ph == null) {
      height = MediaQuery.of(context).size.width / 3 * 2;
    } else {
      height = int.parse(widget.model.ph) *
          MediaQuery.of(context).size.width /
          int.parse(widget.model.pw);
    }

    List<Widget> widgetList = [];
    widgetList.add(
      InkWell(
        child: CachedImage(
          url: widget.model.img!,
          width: MediaQuery.of(context).size.width,
          height: height,
        ),
        onTap: () {
          Navigator.of(context).push(MaterialPageRoute(builder: (_) {
            return CookDetailPage(id: widget.model.id!,imgUrl: widget.model.img,);
          }));
        },
      ),
    );
    if(widget.model.vfurl?.isNotEmpty == true){
      /// 视频
      widgetList.add(
          Positioned(
            bottom: 5,
            right: 5,
            child: Image.asset(
              'assets/images/common/cell_video_play@2x.png',
              width: 32,
              height: 32,
            ),
          )
      );
    }
    return Container(
      color: Colors.white,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          /// 用户头像条
          InkWell(
            child: AvatarRecommendView(
              model: widget.model.a,
            ),
            onTap: () {
              Navigator.of(context).push(MaterialPageRoute(builder: (_) {
                return AuthorPage(
                  model: widget.model,
                );
              }));
            },
          ),

          /// 中间图片
          Stack(
            children: widgetList,
          ),

          /// 收藏用户头像 和 点赞 评论...按钮
          CollectionImageView(
            model: widget.model,
          ),
          Container(
            margin: EdgeInsets.only(left: 10),
            child: Text(
              widget.model.n!,
              style: TextStyle(
                fontSize: 15,
                color: AppColors.deepTextColor,
              ),
            ),
          ),
          SizedBox(
            height: 20,
          )
        ],
      ),
    );
  }
}
